/**
 * Created by kayak-lic on 16/11/9.
 */
import React from 'react';
import util from 'util';
import {Switch,Input,Row,Col,Button,Table ,Modal,Form,Collapse,Card,Radio,Tabs} from 'antd';
import { SearchDemo,RightButton,ColsEdit,Simeditor } from 'kpl';
import sys_dict from "sys_dict";

class BangkaResultSelect extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            tblSource: [],
            isLoading: false,
        };
        this.searchParams = {
            "page": 1,
            "rows": sys_dict.defaultPageSize.toString(),
        };
    }

    refresh(paramdic){
        this.setState({isLoading: true});
        util.httpRequest({type: "POST", url: 'acctlog130301.json',plattype:'app/' , params: paramdic, success: function (result) {
            this.setState({
                tblSource: result.rows,
                totalCount:result.total,
                isLoading: false,
            });
        }.bind(this)});
    }

    search(params){
        params.start_date = util.date2str(params.start_date);
        params.end_date = util.date2str(params.end_date);
        params.page = "1";
        params.rows = sys_dict.defaultPageSize.toString();
        this.refresh(params);
    }

    onShowSizeChange(current, pageSize) {
        let params = this.searchParams;
        params.rows = pageSize;
        params.page = current;
        this.refresh(params);
    }

    onChange(page) {
        let params = this.searchParams;
        params.page = page;
        this.refresh(params);
    }

    componentDidMount(){
        this.refresh(this.searchParams);
    }

    config(){
        const pagination = {
            total: this.state.totalCount,
            showSizeChanger: true,
            showQuickJumper: true,
            isLoading: false,
            pageSizeOptions: sys_dict.pageSizeOptions,
            defaultPageSize: sys_dict.defaultPageSize,
            onShowSizeChange: this.onShowSizeChange.bind(this),
            onChange: this.onChange.bind(this),
        };

        return {
            tableConfig: {
                pagination: pagination,
                dataSource: this.state.tblSource,
                columns: [
                    {
                        title: '流水号',
                        dataIndex: 'trans_serno',
                        key: 'trans_serno',
                    },{
                        title: '姓名',
                        dataIndex: 'user_name',
                        key: 'user_name',
                    },{
                        title: '卡号',
                        dataIndex: 'acct_no',
                        key: 'acct_no',
                    },{
                        title: '身份证',
                        dataIndex: 'id_code',
                        key: 'id_code',
                    }, {
                        title: '绑卡时间',
                        dataIndex: 'trans_date',
                        key: 'trans_date',
                    }]
            },
        }
    }

    render(){

        let config=this.config();
        const searchConfig= {
            searchTitle:"查询条件",
            searchInit:{trans_serno:"",start_date:"",end_date:"",user_id:"",user_name:""},
            searchField: [
                [
                    {propsname:"流水号",propsKey:"trans_serno",propsType:"input",key:"111"},
                    {propsname: "用户姓名", propsKey: "user_name", propsType: "input", key: "114"},

                ],
                [
                    {propsname: "绑卡时间", propsKey: "start_date", propsType: "datepicker", key: "112"},
                    {propsname: "至", propsKey: "end_date", propsType: "datepicker", key: "115"},

                ],
            ]};
        return (
            <div>
                <SearchDemo search={this.search.bind(this)} searchConfig={searchConfig} ></SearchDemo>
                <Table {...config.tableConfig}></Table>
            </div>
        );
    }
}

export default BangkaResultSelect;